package com.example.rubbish.DataBase;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class DataBaseHelper extends SQLiteOpenHelper {

    public static final String CREATE_RECORD ="create table IF NOT EXISTS record(" +
            "id integer primary key autoincrement," +
            "cate_name text," +
            "garbage_name text," +
            "time text ) ";


    public static final String CREATE_INFO ="create table IF NOT EXISTS info(" +
            "id integer primary key autoincrement," +
            "cate_name text," +
            "garbage_name text," +
            "ps text ) ";

    public  static  final String CREATE_HISTORY = "create table   history(" +
            "id integer primary key autoincrement," +
            "history_name text) ";

    public DataBaseHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }


    @Override
    public void onCreate(SQLiteDatabase sqLiteDatabase) {
        sqLiteDatabase.execSQL(CREATE_INFO);
        sqLiteDatabase.execSQL(CREATE_HISTORY);
        sqLiteDatabase.execSQL(CREATE_RECORD);
    }

    //error: no confidence????
    @Override
    public void onUpgrade(SQLiteDatabase sqLiteDatabase, int oldVersion, int newVersion) {
        switch (oldVersion){
            case 1:
                sqLiteDatabase.delete(GDataBase.INFO_DB_NAME,null,null);
                sqLiteDatabase.execSQL(CREATE_INFO);

        }


    }
}
